package com.hu.article.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hu.common.pojo.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 留言表 Mapper 接口
 * </p>
 *
 * @author hu
 * @since 2023-09-10
 */
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("select c.*,u.nickname,u.avatar_url from comment c left join sys_user u on c.user_id = u.id " +
            "where c.blog_id = #{blogId} order by id desc")
    List<Comment> findCommentDetail(@Param("blogId") Integer blogId);

    @Select("select count(*) from comment where pid = #{id} or origin_id = #{id}")
    int countPid(Integer id);

    @Select("select blog_id from comment where id = #{id}")
    int getBlogIdByCommentId(Integer id);
}
